/*
 * @Author: 何 海深 813936564@qq.com
 * @Date: 2022-08-10 20:47:14
 * @LastEditors: 何 海深 813936564@qq.com
 * @LastEditTime: 2024-02-01 16:47:31
 * @FilePath: \show-data-vue3\src\utils\https\asiox.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import servers from './index'
/**
 * @param {String} method  请求的方法：get、post、delete、put
 * @param {String} url     请求的url:
 * @param {Object} data    请求的参数
 * @param {Object} config  请求的配置
 * @returns {Promise}     返回一个promise对象，其实就相当于axios请求数据的返回值
 */
const request = async ({ method, url, data, config }: any): Promise<any> => {
  method = method.toLowerCase()
  if (method == 'post') {
    console.log(config)
    return servers.post(url, data, { ...config })
  } else if (method == 'get') {
    return servers.get(url, {
      params: data,
      ...config
    })
  } else if (method == 'delete') {
    return servers.delete(url, {
      params: data,
      ...config
    })
  } else if (method == 'put') {
    return servers.put(url, data, { ...config })
  } else {
    console.error('未知的method' + method)
    return false
  }
}
export { request }
